layui.use(["table","layer","jquery"],function () {
    var table = layui.table;
    var layer = layui.layer;
    var $ = layui.jquery;

    getTable();
    function getTable(){
        $.ajax({
            url:"/user/getAllUserCoupon",
            data:{},
            type:'post',
            dataType:'json',
            success:function (data) {
                demoTable(data.data);
            }
        });
    }
    function demoTable(data){
        table.render({
            elem:"#tableDemo",
            data:data,
            width:1000,
            cols:[[
                {type:'radio'},
                {field:"couponName",title:"优惠券名称",align:"center",width:190},
                {field:"couponPrice",title:"优惠金额",align:"center",width:190},
                {field:"type",title:"使用类型",align:"center",width:190,templet:function (data) {
                        if (data.type == 2){
                            return "商品";
                        } else{
                            return "视频";
                        }
                    }},
                {field:"startDate",title:"开始时间",align:"center",width:190},
                {field:"endDate",title:"到期时间",align:"center",width:184}
            ]],
            page:true

        });

        table.on("radio(tableDemo)",function (obj) {
            localStorage.setItem("couponId",obj.data.couponId);
        });

    }
})